package com.practice.tetris.config;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.net.URL;
import java.util.List;

/**
 * Author: Zhouyue
 * Date: 2015/6/9 23:24
 */
public class ConfigDemo {

    public static void main(String[] args) throws Exception {
        readConfig();
    }

    public static void readConfig() throws Exception {
        URL cfgUrl = ConfigDemo.class.getResource("/cfg.xml");
        SAXReader reader = new SAXReader();
        Document doc = reader.read(cfgUrl);
        Element game = doc.getRootElement();
        Element frame = game.element("frame");
        System.out.println(frame.attributeValue("width"));
        List<Element> layers = frame.elements("layer");
        System.out.println("there are " + layers.size() + " layers");
        for (Element element : layers) {
            System.out.println("x: " + element.attributeValue("x"));
            System.out.println("y: " + element.attributeValue("y"));
            System.out.println("width: " + element.attributeValue("width"));
            System.out.println("height: " + element.attributeValue("height"));
        }
    }
}
